package com.RPC.server.handler;

import com.RPC.server.ask.UserReq;
import com.RPC.server.ask.UserRes;
import com.google.common.util.concurrent.Futures;
import com.yaxon.vndp.rpc.Message;
import com.yaxon.vndp.rpc.MessageHandler;
import com.google.common.util.concurrent.ListenableFuture;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Author: <黄书根>
 * Time: 2017-08-04 14:43
 * Copyright (C) 2017 Xiamen Yaxon Networks CO.,LTD.
 */
@Service
public class UserHandler implements MessageHandler {
    @Override
    public ListenableFuture<Message> handle(Message request) {
        if (request instanceof UserReq) {
            UserReq req = (UserReq) request;
            return this.getUser(req);
        }
        else{
            throw new RuntimeException("未知的请求消息类型: " + request.getClass().getName());
        }
    }
    public ListenableFuture<Message> getUser(UserReq req) {
        UserRes res=new UserRes();
        List<String> list=new ArrayList();
        list.add("成");
        list.add("功");
        list.add("!");
        res.setList(list);
        return  Futures.<Message>immediateFuture(res);
    }

}
